package com.gmail.jaredjeya.awesomeplatformer.model.entity.mob;

import android.util.Log;

import com.gmail.jaredjeya.awesomeplatformer.Constants;
import com.gmail.jaredjeya.awesomeplatformer.model.Game;
import com.gmail.jaredjeya.awesomeplatformer.model.InputHandler;
import com.gmail.jaredjeya.awesomeplatformer.model.sprites.Sprite;

public class Player extends Mob {
	
	public int deaths;
	private InputHandler inputHandler;

	public Player(Sprite sprite, float xPos, float yPos, InputHandler inputHandler) {
		super(sprite, xPos, yPos, Constants.PLAYER_SIZE / (2F * Constants.GRID_SIZE), Constants.PLAYER_SIZE / (2F * Constants.GRID_SIZE), true);
		this.inputHandler = inputHandler;
	}
	
	@Override
	public void update(Game game) {
		if(!isLiving){
			this.xPos = game.getCurrentLevel().spawnX;
			Log.v(Constants.DEBUG_TAG, this.xPos + " " + game.getCurrentLevel().spawnX);
			this.yPos = game.getCurrentLevel().spawnY;
			Log.v(Constants.DEBUG_TAG, this.yPos + " " + game.getCurrentLevel().spawnY);
			isLiving = true;
			deaths++;
		}
		
		if(inside(game.getCurrentLevel().goalX, game.getCurrentLevel().goalY)) {
			sprite = Sprite.redSprite;
		}
		
		super.update(game);
		setXVelocity(0);
		if(inputHandler.leftPressed) setXVelocity(-4F);
		if(inputHandler.rightPressed) setXVelocity(+4F);
		
		if(inputHandler.jumpPressed && touchingGround) setYVelocity(-10F);
		else accelerate(0F, +9.8F);
	}
}
